package com.nine.news.response;

import lombok.Data;

/**
 * @Author: szhan
 * @Date: 2023/03/15/8:33 AM
 * @Description:
 */
@Data
public class R {
    private static final String SUCCESS_MESSAGE = "请求成功";

    private static final String ERROR_MESSAGE = "网络异常";

    private static final Integer SUCCESS_CODE = 0;

    private static final Integer ERROR_CODE = 500;

    private Integer code;

    private String message;

    private Object data;

    public R() {
    }

    public R(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static R OK() {
        return new R(SUCCESS_CODE, SUCCESS_MESSAGE, null);
    }

    public static R OK(Object data) {
        return new R(SUCCESS_CODE, SUCCESS_MESSAGE, data);
    }

    public static R ERROR() {
        return new R(ERROR_CODE, ERROR_MESSAGE, null);
    }

    public static R ERROR(String message) {
        return new R(ERROR_CODE, message, null);
    }

    public static R ERROR(Object data) {
        return new R(ERROR_CODE, ERROR_MESSAGE, data);
    }

    public static R ERROR(String message,Object data) {
        return new R(ERROR_CODE, message, data);
    }

    public R ERROR(Integer code,String message,Object data) {
        return new R(code, message, data);
    }
}
